﻿@if (!string.IsNullOrWhiteSpace(ViewBag.Message))
{
    @Html.Partial("Message")
}
<div class="widget white-t">
    <div class="header">
        <div class="icon">
        </div>
        <span>
            @ForumContext.GetText(LanguageSection.SEARCH, "SEARCH_ADVANCED")
        </span>
    </div>
    <form action="@ForumContext.GetAbsoluteUrl(ForumUrls.SEARCH)" class="ajax">
    @Html.AntiForgeryToken()
    <table>
        <tr>
            <td class="table-cell w50 v-top">
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "BY_KEYWORDS")
                    </legend>
                    <div class="p-10">
                        <select id="_searchwithin" name="_searchwithin" class="select" style="width: 30%">
                            <option value="0">
                                @ForumContext.GetText(LanguageSection.SEARCH, "WITH_IN_ALL")</option>
                            <option value="1">
                                @ForumContext.GetText(LanguageSection.SEARCH, "WITH_IN_SUBJECT")</option>
                            <option value="2">
                                @ForumContext.GetText(LanguageSection.SEARCH, "WITH_IN_MESSAGE")</option>
                        </select>
                        @Html.TextBox("_kwd", Request.QueryString["kwd"], new { @class = "input {validate:{required:true,minlength:3}}", @style = "width:60%" })
                    </div>
                </fieldset>
            </td>
            <td class="table-cell v-top">
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "BY_USERS")
                    </legend>
                    <div class="p-10">
                        <select id="_SearchKeywordType" name="_SearchKeywordType" style="width: 20%" class="select">
                            <option value="0">
                                @ForumContext.GetText(LanguageSection.SEARCH, "INCLUDE")</option>
                            <option value="1">
                                @ForumContext.GetText(LanguageSection.SEARCH, "STARTWITH")</option>
                            <option value="2">
                                @ForumContext.GetText(LanguageSection.SEARCH, "ENDWITH")</option>
                            <option value="3">
                                @ForumContext.GetText(LanguageSection.SEARCH, "EXACT")</option>
                        </select>
                        @Html.TextBox("_username", "", new { @class = "input", @style = "width:70%" })
                    </div>
                </fieldset>
            </td>
        </tr>
        <tr>
            <td class="caption" colspan="2">
                @ForumContext.GetText(LanguageSection.SEARCH, "OTHER_OPTIONS")
            </td>
        </tr>
        <tr>
            <td class="table-cell v-top">
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "POSTS_WITH")</legend>
                    <div class="p-10">
                        <select id="_SearchPostsWith" name="_SearchPostsWith" class="select w20">
                            <option value="0">
                                @ForumContext.GetText(LanguageSection.SEARCH, "ATLEAST")</option>
                            <option value="1">
                                @ForumContext.GetText(LanguageSection.SEARCH, "ATMOST")</option>
                        </select>
                        @Html.TextBox("_Replies", "0", new { @class = "input {validate:{digits:true}}", @style = "width:30px" })
                        @ForumContext.GetText(LanguageSection.SEARCH, "REPLY")
                    </div>
                </fieldset>
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "FIND_POSTS_FROM")</legend>
                    <select id="_findPostsFrom" name="_findPostsFrom" class="select">
                        <option value="0">
                            @ForumContext.GetText(LanguageSection.SEARCH, "ANYDATE")</option>
                        <option value="1">
                            @ForumContext.GetText(LanguageSection.SEARCH, "YESTERDAY")</option>
                        @{
                            string _dayAgo = ForumContext.GetText(LanguageSection.SEARCH, "DAYSAGO");
                            for (int i = 5; i < 90; i += 5)
                            {


                            <option value="@i">
                                @String.Format(_dayAgo, i)</option>
                       
                            }
                        }
                    </select>
                    <select id="_findPostsTo" name="_findPostsTo" style="width: 100px" disabled="disabled"
                        class="select">
                        <option value="0">
                            @ForumContext.GetText(LanguageSection.SEARCH, "AND_NEWER")</option>
                        <option value="1">
                            @ForumContext.GetText(LanguageSection.SEARCH, "AND_OLDER")</option>
                    </select>
                </fieldset>
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "RESULTS_SORT_BY")</legend>
                    <select id="_sortby" name="_sortby" class="select">
                        <option value="1">
                            @ForumContext.GetText(LanguageSection.SEARCH, "LASTPOSTED")</option>
                        <option value="2">
                            @ForumContext.GetText(LanguageSection.SEARCH, "CREATED")</option>
                        <option value="3">
                            @ForumContext.GetText(LanguageSection.SEARCH, "SUBJECT")</option>
                        <option value="4">
                            @ForumContext.GetText(LanguageSection.SEARCH, "TOTALREPLIES")</option>
                        <option value="5">
                            @ForumContext.GetText(LanguageSection.SEARCH, "TOTALVIEWS")</option>
                        <option value="6">
                            @ForumContext.GetText(LanguageSection.SEARCH, "LASTEDITED")</option>
                    </select>
                    <select id="_sortorder" name="_sortorder" style="width: 100px" class="select">
                        <option value="ASC">
                            @ForumContext.GetText(LanguageSection.SEARCH, "ASC")</option>
                        <option value="DESC">
                            @ForumContext.GetText(LanguageSection.SEARCH, "DESC")</option>
                    </select>
                </fieldset>
                <fieldset>
                    <legend>
                        @ForumContext.GetText(LanguageSection.SEARCH, "SHOW_RESULTS_AS")</legend>
                    <select id="_ShowResultsAs" name="_ShowResultsAs" class="select">
                        <option value="0">
                            @ForumContext.GetText(LanguageSection.SEARCH, "TOPICS")</option>
                        <option value="1" disabled="disabled">
                            @ForumContext.GetText(LanguageSection.SEARCH, "POSTS")</option>
                    </select>
                </fieldset>
            </td>
            <td class="table-cell v-top">
                <select style="width: 100%; height: 300px; margin-bottom: 8px;" multiple="multiple"
                    id="_forums" name="_forums">
                    <option value="0" class="bold" selected="selected">@ForumContext.GetText(LanguageSection.SEARCH, "ALL_FORUMS")</option>
                    @{
                        var _forums = ForumRepo.ListAll();


                        foreach (Forum f in _forums)
                        {
                            if (ForumContext.ForumAllowRoles(f.AllowRoles))
                            {
                        @Html.Raw(String.Format("<option value=\"{0}\" class=\"{1}\">{2}{3}</option>", f.ForumId, f.ParentId == 0 ? "bold" : string.Empty, ForumContext.Padding(f.Level), Html.Encode(f.ForumName)))
                            }
                        }
                    }
                </select>
                @* @Html.ListBox("_forums", (IEnumerable<SelectListItem>)(ViewBag.ForumList), new { style = "width: 100%; height: 280px; margin-bottom: 8px;" })*@
                @*  <br />
                <input type="checkbox" id="_issearchinsubforums" name="_issearchinsubforums" checked="checked" /><label
                    for="_issearchinsubforums">@ForumContext.GetText(LanguageSection.SEARCH, "SEARCH_IN_SUB_FORUMS")</label>*@
            </td>
        </tr>
        <tr>
            <td class="table-cell center" colspan="2">
                @Html.Button(ButtonType.Submit, ForumContext.GetText(LanguageSection.SEARCH, "GO"), new { @class = "ui-button icon-16 go" })
            </td>
        </tr>
    </table>
    </form>
</div>
@using (Html.BeginScriptBlock())
{
    
    <script type="text/javascript">

        $(function () {

            $('#_findPostsTo').attr("disabled", $('#_findPostsFrom').val() == 0);

            $('#_findPostsFrom').unbind(".mvcforum").bind('change.mvcforum', function () {

                $('#_findPostsTo').attr("disabled", this.value == 0);
            });

        });
    </script>
}
